package com.proj.hot.login;



import java.util.HashMap;

import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class SAXhandler extends DefaultHandler {
    private StringBuffer buf;
    private String str;
    private HashMap<String, String> hashMap = new HashMap<String, String>();

    public SAXhandler() {
	super();
    }

    public HashMap<String, String> getHashMap() {
	return hashMap;
    }

    public void startDocument() throws SAXException {
	buf = new StringBuffer();
	// System.out.println("*******开始解析XML*******");
    }

    public void endDocument() throws SAXException {
	// System.out.println("*******XML解析结束*******");
    }

    public void endElement(String namespaceURI, String localName,
	    String fullName) throws SAXException {
	str = buf.toString();
	/*
	 * System.out.println("节点=" + fullName + "/value=" + buf + " 长度=" +
	 * buf.length());
	 */
	// System.out.println(buf);
	if (!fullName.equals("Response")) {
	    hashMap.put(fullName, str);
	}
	// System.out.println(hashMap);
	buf.delete(0, buf.length());
    }

    public void characters(char[] chars, int start, int length)
	    throws SAXException {
	// 将元素内容累加到StringBuffer中
	buf.append(chars, start, length);
    }

}
